package com.learn.singleton;

import lombok.extern.slf4j.Slf4j;

/**
 * <p>项目名称: design-pattern </p>
 *
 * <p>文件名称: App </p>
 *
 */
@Slf4j
public class App {
    public static void main(String[] args) {
        // eagerly initialized singleton
        Singleton s1 = Singleton.getInstance();
        Singleton s2 = Singleton.getInstance();
        log.info("s1 = {}", s1);
        log.info("s2 = {}", s2);

        // lazily initialized singleton
        ThreadSafeLazyLoadedSingleton tslls1 = ThreadSafeLazyLoadedSingleton.getInstance();
        ThreadSafeLazyLoadedSingleton tslls2 = ThreadSafeLazyLoadedSingleton.getInstance();
        log.info("tslls1={}", tslls1);
        log.info("tslls2={}", tslls2);

        // enum singleton
        EnumSingleton e1 = EnumSingleton.INSTANCE;
        EnumSingleton e2 = EnumSingleton.INSTANCE;
        log.info("e1 = {}", e1);
        log.info("e2 = {}", e2);


        // double checked locking
        ThreadSafeDoubleCheckLocking tsfcl1 = ThreadSafeDoubleCheckLocking.getInstance();
        log.info("tsfcl1 = {}", tsfcl1);
        ThreadSafeDoubleCheckLocking tsfcl2 = ThreadSafeDoubleCheckLocking.getInstance();
        log.info("tsfcl2 = {}", tsfcl2);

        // initialize on demand holder idiom
        InitializingOnDemandHolderIdiom iodhd1 = InitializingOnDemandHolderIdiom.getInstance();
        log.info("iodhd1 = {}", iodhd1);
        InitializingOnDemandHolderIdiom iodhd2 = InitializingOnDemandHolderIdiom.getInstance();
        log.info("iodhd2 = {}", iodhd2);
    }
}
